<?php


abstract class BaseSesionAsesoria extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $asesor_id;


	
	protected $estudiante_id;


	
	protected $fecha;


	
	protected $turno_id;


	
	protected $conclusiones;


	
	protected $hora;


	
	protected $causa_rend_actual;

	
	protected $aAteneausuario;

	
	protected $aDatoEstudiante;

	
	protected $aTurno;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getAsesorId()
	{

		return $this->asesor_id;
	}

	
	public function getEstudianteId()
	{

		return $this->estudiante_id;
	}

	
	public function getFecha($format = 'Y-m-d')
	{

		if ($this->fecha === null || $this->fecha === '') {
			return null;
		} elseif (!is_int($this->fecha)) {
						$ts = strtotime($this->fecha);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha] as date/time value: " . var_export($this->fecha, true));
			}
		} else {
			$ts = $this->fecha;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getTurnoId()
	{

		return $this->turno_id;
	}

	
	public function getConclusiones()
	{

		return $this->conclusiones;
	}

	
	public function getHora($format = 'H:i:s')
	{

		if ($this->hora === null || $this->hora === '') {
			return null;
		} elseif (!is_int($this->hora)) {
						$ts = strtotime($this->hora);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [hora] as date/time value: " . var_export($this->hora, true));
			}
		} else {
			$ts = $this->hora;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCausaRendActual()
	{

		return $this->causa_rend_actual;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::ID;
		}

	} 
	
	public function setAsesorId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->asesor_id !== $v) {
			$this->asesor_id = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::ASESOR_ID;
		}

		if ($this->aAteneausuario !== null && $this->aAteneausuario->getId() !== $v) {
			$this->aAteneausuario = null;
		}

	} 
	
	public function setEstudianteId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->estudiante_id !== $v) {
			$this->estudiante_id = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::ESTUDIANTE_ID;
		}

		if ($this->aDatoEstudiante !== null && $this->aDatoEstudiante->getId() !== $v) {
			$this->aDatoEstudiante = null;
		}

	} 
	
	public function setFecha($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha !== $ts) {
			$this->fecha = $ts;
			$this->modifiedColumns[] = SesionAsesoriaPeer::FECHA;
		}

	} 
	
	public function setTurnoId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->turno_id !== $v) {
			$this->turno_id = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::TURNO_ID;
		}

		if ($this->aTurno !== null && $this->aTurno->getId() !== $v) {
			$this->aTurno = null;
		}

	} 
	
	public function setConclusiones($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->conclusiones !== $v) {
			$this->conclusiones = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::CONCLUSIONES;
		}

	} 
	
	public function setHora($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [hora] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->hora !== $ts) {
			$this->hora = $ts;
			$this->modifiedColumns[] = SesionAsesoriaPeer::HORA;
		}

	} 
	
	public function setCausaRendActual($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->causa_rend_actual !== $v) {
			$this->causa_rend_actual = $v;
			$this->modifiedColumns[] = SesionAsesoriaPeer::CAUSA_REND_ACTUAL;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->asesor_id = $rs->getInt($startcol + 1);

			$this->estudiante_id = $rs->getInt($startcol + 2);

			$this->fecha = $rs->getDate($startcol + 3, null);

			$this->turno_id = $rs->getInt($startcol + 4);

			$this->conclusiones = $rs->getString($startcol + 5);

			$this->hora = $rs->getTime($startcol + 6, null);

			$this->causa_rend_actual = $rs->getString($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating SesionAsesoria object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SesionAsesoriaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			SesionAsesoriaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SesionAsesoriaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aAteneausuario !== null) {
				if ($this->aAteneausuario->isModified()) {
					$affectedRows += $this->aAteneausuario->save($con);
				}
				$this->setAteneausuario($this->aAteneausuario);
			}

			if ($this->aDatoEstudiante !== null) {
				if ($this->aDatoEstudiante->isModified()) {
					$affectedRows += $this->aDatoEstudiante->save($con);
				}
				$this->setDatoEstudiante($this->aDatoEstudiante);
			}

			if ($this->aTurno !== null) {
				if ($this->aTurno->isModified()) {
					$affectedRows += $this->aTurno->save($con);
				}
				$this->setTurno($this->aTurno);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = SesionAsesoriaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += SesionAsesoriaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aAteneausuario !== null) {
				if (!$this->aAteneausuario->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aAteneausuario->getValidationFailures());
				}
			}

			if ($this->aDatoEstudiante !== null) {
				if (!$this->aDatoEstudiante->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aDatoEstudiante->getValidationFailures());
				}
			}

			if ($this->aTurno !== null) {
				if (!$this->aTurno->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTurno->getValidationFailures());
				}
			}


			if (($retval = SesionAsesoriaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SesionAsesoriaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getAsesorId();
				break;
			case 2:
				return $this->getEstudianteId();
				break;
			case 3:
				return $this->getFecha();
				break;
			case 4:
				return $this->getTurnoId();
				break;
			case 5:
				return $this->getConclusiones();
				break;
			case 6:
				return $this->getHora();
				break;
			case 7:
				return $this->getCausaRendActual();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SesionAsesoriaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getAsesorId(),
			$keys[2] => $this->getEstudianteId(),
			$keys[3] => $this->getFecha(),
			$keys[4] => $this->getTurnoId(),
			$keys[5] => $this->getConclusiones(),
			$keys[6] => $this->getHora(),
			$keys[7] => $this->getCausaRendActual(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SesionAsesoriaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setAsesorId($value);
				break;
			case 2:
				$this->setEstudianteId($value);
				break;
			case 3:
				$this->setFecha($value);
				break;
			case 4:
				$this->setTurnoId($value);
				break;
			case 5:
				$this->setConclusiones($value);
				break;
			case 6:
				$this->setHora($value);
				break;
			case 7:
				$this->setCausaRendActual($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SesionAsesoriaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setAsesorId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setEstudianteId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFecha($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setTurnoId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setConclusiones($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setHora($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCausaRendActual($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(SesionAsesoriaPeer::DATABASE_NAME);

		if ($this->isColumnModified(SesionAsesoriaPeer::ID)) $criteria->add(SesionAsesoriaPeer::ID, $this->id);
		if ($this->isColumnModified(SesionAsesoriaPeer::ASESOR_ID)) $criteria->add(SesionAsesoriaPeer::ASESOR_ID, $this->asesor_id);
		if ($this->isColumnModified(SesionAsesoriaPeer::ESTUDIANTE_ID)) $criteria->add(SesionAsesoriaPeer::ESTUDIANTE_ID, $this->estudiante_id);
		if ($this->isColumnModified(SesionAsesoriaPeer::FECHA)) $criteria->add(SesionAsesoriaPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(SesionAsesoriaPeer::TURNO_ID)) $criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->turno_id);
		if ($this->isColumnModified(SesionAsesoriaPeer::CONCLUSIONES)) $criteria->add(SesionAsesoriaPeer::CONCLUSIONES, $this->conclusiones);
		if ($this->isColumnModified(SesionAsesoriaPeer::HORA)) $criteria->add(SesionAsesoriaPeer::HORA, $this->hora);
		if ($this->isColumnModified(SesionAsesoriaPeer::CAUSA_REND_ACTUAL)) $criteria->add(SesionAsesoriaPeer::CAUSA_REND_ACTUAL, $this->causa_rend_actual);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(SesionAsesoriaPeer::DATABASE_NAME);

		$criteria->add(SesionAsesoriaPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setAsesorId($this->asesor_id);

		$copyObj->setEstudianteId($this->estudiante_id);

		$copyObj->setFecha($this->fecha);

		$copyObj->setTurnoId($this->turno_id);

		$copyObj->setConclusiones($this->conclusiones);

		$copyObj->setHora($this->hora);

		$copyObj->setCausaRendActual($this->causa_rend_actual);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new SesionAsesoriaPeer();
		}
		return self::$peer;
	}

	
	public function setAteneausuario($v)
	{


		if ($v === null) {
			$this->setAsesorId(NULL);
		} else {
			$this->setAsesorId($v->getId());
		}


		$this->aAteneausuario = $v;
	}


	
	public function getAteneausuario($con = null)
	{
				include_once 'lib/model/om/BaseAteneausuarioPeer.php';

		if ($this->aAteneausuario === null && ($this->asesor_id !== null)) {

			$this->aAteneausuario = AteneausuarioPeer::retrieveByPK($this->asesor_id, $con);

			
		}
		return $this->aAteneausuario;
	}

	
	public function setDatoEstudiante($v)
	{


		if ($v === null) {
			$this->setEstudianteId(NULL);
		} else {
			$this->setEstudianteId($v->getId());
		}


		$this->aDatoEstudiante = $v;
	}


	
	public function getDatoEstudiante($con = null)
	{
				include_once 'lib/model/om/BaseDatoEstudiantePeer.php';

		if ($this->aDatoEstudiante === null && ($this->estudiante_id !== null)) {

			$this->aDatoEstudiante = DatoEstudiantePeer::retrieveByPK($this->estudiante_id, $con);

			
		}
		return $this->aDatoEstudiante;
	}

	
	public function setTurno($v)
	{


		if ($v === null) {
			$this->setTurnoId(NULL);
		} else {
			$this->setTurnoId($v->getId());
		}


		$this->aTurno = $v;
	}


	
	public function getTurno($con = null)
	{
				include_once 'lib/model/om/BaseTurnoPeer.php';

		if ($this->aTurno === null && ($this->turno_id !== null)) {

			$this->aTurno = TurnoPeer::retrieveByPK($this->turno_id, $con);

			
		}
		return $this->aTurno;
	}

} 